import java.io.PrintStream;

public class Task {
    public static void main(String[] args) {
        run("lesson9/task18/src/out.txt");
    }

    public static void run(String fileName) {
        try (
            PrintStream ps = new PrintStream(fileName);
        ) {
            System.setOut(ps);
            System.out.println("Hello, world!");
        } catch (Exception e) {
            System.out.println("Exception has been caught");
        }
    }
}